package com.zsy.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 权限拦截器
 * @author zhousuying
 *
 */
public class LoginFilter implements Filter {

	public void destroy() {
		// TODO Auto-generated method stub

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest hs = (HttpServletRequest) request;
		//判断用户是否登录
		String user = (String) hs.getSession().getAttribute("user");
		if (null != user) {
			chain.doFilter(request, response);
		}else {
			HttpServletResponse hsr = (HttpServletResponse) response;
			hsr.sendRedirect(hs.getContextPath() + "/admin/index.html");
		}
	}

	public void init(FilterConfig filterConfig) throws ServletException {
	}

}
